#ifndef _DYNAMICARRAY_H_
#define _DYNAMICARRAY_H_

#include<stddef.h>

using ElementType = void*;
class DynamicArray
{
public:
    DynamicArray( size_t capacity = 15);
    DynamicArray(const DynamicArray&a);
    DynamicArray& operator=(const DynamicArray& a);
    ~DynamicArray();

    size_t Size();
    void ReSize(size_t capacity); 

    void InsertTail(const ElementType& element);
    void InsertHead(const ElementType& element);
    void InsertByIndex(int index, const ElementType& element);

    void RemoveByIndex(int index);
    void RemoveByElement(const ElementType& element);

    ElementType* FindByIndex(int index);
    DynamicArray FindByElement(const ElementType& element);
    void showIndex();

    void UpdateByIndex(int index, const ElementType& element);
    void UpdateByElement(const ElementType& oldValue, const ElementType& newValue);

    void Sort();
    void Duplicate();
    DynamicArray Merge(const DynamicArray& a); //归并算法
    DynamicArray FdInterScth(const DynamicArray& a);
    DynamicArray FdUnionSet(const DynamicArray& a);
    DynamicArray FdDifference(const DynamicArray& a);
    DynamicArray subsequence(int index, size_t size);

    bool operator==(const DynamicArray& a);

    size_t BinarySearch(const ElementType& element);
    bool IsChild(const DynamicArray& a);
    bool IsCntnsChils(const DynamicArray& a);

    void show();
    void SetFreePtr(void (*freeptr)(ElementType));
    void SetPrintPtr(void (*PrintPtr)(ElementType));
    void SetSortPtr(int (*SortPtr)(ElementType,ElementType));
    void SetEqualPtr(bool (*EqualPtr)(ElementType,ElementType));
private:
    void FastSort(size_t start, size_t end,size_t deepth, size_t MaxDeepth);
    void InsertSort(size_t start, size_t end);

    size_t Partition(size_t start, size_t end);
    ElementType *array;
    size_t capacity;
    size_t size;
    void (*freeptr)(ElementType); //数组元素释放指针
    void (*PrintPtr)(ElementType);//打印数组元素指针
    int (*SortPtr)(ElementType,ElementType);//排序指针
    bool (*EqualPtr)(ElementType,ElementType);//比较指针
};

#endif